<!DOCTYPE html>
<html lang="zh-cn">
<head>
   
    <link type="text/css" rel="stylesheet" href="/bundles/blog-common.css?v=KOZafwuaDasEedEenI5aTy8aXH0epbm6VUJ0v3vsT_Q1"/>
<link id="MainCss" type="text/css" rel="stylesheet" href="/skins/ThinkInside/bundle-ThinkInside.css?v=RRjf6pEarGnbXZ86qxNycPfQivwSKWRa4heYLB15rVE1"/>
<link type="text/css" rel="stylesheet" href="/blog/customcss/428549.css?v=%2fam3bBTkW5NBWhBE%2fD0lcyJv5UM%3d"/>

</head>
<body>
<a name="top"></a>

<div id="page_begin_html"></div><script>load_page_begin_html();</script>

<div id="topics">
	<div class = "post">
		<h1 class = "postTitle">
			<a id="cb_post_title_url" class="postTitle2" href="https://www.cnblogs.com/frankdeng/p/9584870.html">Kafka集群管理工具kafka-manager的安装使用</a>
		</h1>
		<div class="clear"></div>
		<div class="postBody">
			<div id="cnblogs_post_body" class="blogpost-body"><h2>一.kafka-manager简介</h2>
<p>&nbsp; &nbsp; kafka-manager是目前最受欢迎的kafka集群管理工具，最早由雅虎开源，用户可以在Web界面执行一些简单的集群管理操作。具体支持以下内容：</p>
<ul>
<li><span>管理多个集群</span></li>
<li><span>轻松检查群集状态（主题，消费者，偏移，代理，副本分发，分区分发）</span></li>
<li><span>运行首选副本选举</span></li>
<li><span>使用选项生成分区分配以选择要使用的代理</span></li>
<li><span>运行分区重新分配（基于生成的分配）</span></li>
<li><span>使用可选主题配置创建主题（0.8.1.1具有与0.8.2+不同的配置）</span></li>
<li><span>删除主题（仅支持0.8.2+并记住在代理配​​置中设置delete.topic.enable = true）</span></li>
<li><span>主题列表现在指示标记为删除的主题（仅支持0.8.2+）</span></li>
<li><span>批量生成多个主题的分区分配，并可选择要使用的代理</span></li>
<li><span>批量运行重新分配多个主题的分区</span></li>
<li><span>将分区添加到现有主题</span></li>
<li><span>更新现有主题的配置</span></li>
</ul>
<p>kafka-manager&nbsp;项目地址：<a href="https://github.com/yahoo/kafka-manager" target="_blank">https://github.com/yahoo/kafka-manager</a></p>
<h2>二.kafka-manager安装</h2>
<h3>1.下载安装包</h3>
<p>使用Git或者直接从Releases中下载，这里我们下载 1.3.3.18 版本：<a href="https://github.com/yahoo/kafka-manager/releases" target="_blank">https://github.com/yahoo/kafka-manager/releases</a></p>
<p><img src="https://img2018.cnblogs.com/blog/1385722/201809/1385722-20180904164911743-1575461220.png" alt="" /></p>
<div class="cnblogs_code">
<pre>[admin@node21 software]$ wget https:<span style="color: #008000;">//</span><span style="color: #008000;">github.com/yahoo/kafka-manager/archive/1.3.3.18.zip</span></pre>
</div>
<h3>2.解压安装包</h3>
<div class="cnblogs_code">
<pre>[admin@node21 software]$ mv <span style="color: #800080;">1.3</span>.<span style="color: #800080;">3.18</span>.zip kafka-manager-<span style="color: #800080;">1.3</span>.<span style="color: #800080;">3.18</span><span style="color: #000000;">.zip
[admin@node21 software]$ unzip kafka</span>-manager-<span style="color: #800080;">1.3</span>.<span style="color: #800080;">3.18</span>.zip -d /opt/module/<span style="color: #000000;">
[admin@node21 software]$ cd </span>/opt/module/<span style="color: #000000;">
[admin@node21 module]$ ll
drwxr</span>-xr-x  <span style="color: #800080;">9</span> admin admin   <span style="color: #800080;">268</span> May <span style="color: #800080;">27</span> <span style="color: #800080;">00</span>:<span style="color: #800080;">33</span> jdk1.<span style="color: #800080;">8</span><span style="color: #000000;">
drwxr</span>-xr-x  <span style="color: #800080;">7</span> admin admin   <span style="color: #800080;">122</span> Jun <span style="color: #800080;">14</span> <span style="color: #800080;">11</span>:<span style="color: #800080;">44</span> kafka_2.<span style="color: #800080;">11</span>-<span style="color: #800080;">1.1</span>.<span style="color: #800080;">0</span><span style="color: #000000;">
drwxrwxr</span>-x  <span style="color: #800080;">9</span> admin admin   <span style="color: #800080;">189</span> Jul  <span style="color: #800080;">7</span> <span style="color: #800080;">04</span>:<span style="color: #800080;">44</span> kafka-manager-<span style="color: #800080;">1.3</span>.<span style="color: #800080;">3.18</span><span style="color: #000000;">
drwxr</span>-xr-x <span style="color: #800080;">11</span> admin admin  <span style="color: #800080;">4096</span> May <span style="color: #800080;">29</span> <span style="color: #800080;">10</span>:<span style="color: #800080;">14</span> zookeeper-<span style="color: #800080;">3.4</span>.<span style="color: #800080;">12</span><span style="color: #000000;">
[admin@node21 module]$ ls kafka</span>-manager-<span style="color: #800080;">1.3</span>.<span style="color: #800080;">3.18</span>/<span style="color: #000000;">
app build.sbt conf img LICENCE</span> project <span style="color: #0000ff;">public</span> README.md <span style="color: #ff0000;">sbt</span> src target test</pre>
</div>
<h3>3.sbt编译</h3>
<p>1）yum安装sbt(因为kafka-manager需要sbt编译)</p>
<div class="cnblogs_code">
<pre>[admin@node21 ~]$ curl https:<span style="color: #008000;">//</span><span style="color: #008000;">bintray.com/sbt/rpm/rpm &gt; bintray-sbt-rpm.repo</span>
[admin@node21 ~]$ sudo mv bintray-sbt-rpm.repo /etc/yum.repos.d/<span style="color: #000000;">
[admin@node21 </span>~]$ sudo yum install sbt</pre>
</div>
<p>修改仓库地址：（sbt 默认下载库文件很慢, 还时不时被打断），我们可以在用户目录下创建 touch ~/.sbt/repositories, 填上阿里云的镜像&nbsp;&nbsp; # vi ~/.sbt/repositories&nbsp;&nbsp;</p>
<div class="cnblogs_code">
<pre>[repositories] <br />local <br />aliyun: http:<span style="color: #008000;">//</span><span style="color: #008000;">maven.aliyun.com/nexus/content/groups/public/<br />typesafe: </span><span style="color: #008000; text-decoration: underline;">http://repo.typesafe.com/typesafe/ivy-releases/</span><span style="color: #008000;">, [organization]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext], bootOnly <br />sonatype-oss-releases <br />maven-central <br />sonatype-oss-snapshots</span></pre>
</div>
<p>验证：检查sbt是否安装成功，查看命令输出，发现已经成功可以从<code>maven.aliyun.com/nexus</code>下载到依赖即表示成功</p>
<div class="cnblogs_code">
<pre>[admin@node21 ~]$ sbt-version</pre>
</div>
<p>2）编译kafka-manager</p>
<div class="cnblogs_code">
<pre>[admin@node21 kafka-manager-<span style="color: #800080;">1.3</span>.<span style="color: #800080;">3.18</span>]$ ./sbt clean dist</pre>
</div>
<p>看到打印这个消息 Getting org.scala-sbt sbt 0.13.9&nbsp; (this may take some time)... 就慢慢等吧，可以到~/.sbt/boot/update.log 查看sbt更新日志。sbt更新好，就开始下载各种jar包，最后看到：Your package is ready in /opt/module/kafka-manager-1.3.3.18/target/universal/kafka-manager-1.3.3.18.zip&nbsp; 证明编译好了。</p>
<p><img src="https://img2018.cnblogs.com/blog/1385722/201809/1385722-20180904212805324-1278560120.png" alt="" /></p>
<h3>4.安装</h3>
<p>环境准备：Java 8+&nbsp; &nbsp; &nbsp;kafka集群搭建参考：<a id="cb_post_title_url" class="postTitle2" href="https://www.cnblogs.com/frankdeng/p/9403883.html" target="_blank">CentOS7.5搭建Kafka2.11-1.1.0集群</a>&nbsp; &nbsp; &nbsp;&nbsp;</p>
<h4>重新解压编译好的kafka-manager-1.3.3.18.zip</h4>
<div class="cnblogs_code">
<pre>[admin@node21 kafka-manager-<span style="color: #800080;">1.3</span>.<span style="color: #800080;">3.18</span><span style="color: #000000;">]$ ls
bin  conf  lib  README.md  share</span></pre>
</div>
<h4>修改配置文件</h4>
<div class="cnblogs_code">
<pre>[admin@node21 kafka-manager-<span style="color: #800080;">1.3</span>.<span style="color: #800080;">3.18</span><span style="color: #000000;">]$ pwd
</span>/opt/module/kafka-manager-<span style="color: #800080;">1.3</span>.<span style="color: #800080;">3.18</span><span style="color: #000000;">
[admin@node21 kafka</span>-manager-<span style="color: #800080;">1.3</span>.<span style="color: #800080;">3.18</span>]$ ls conf/<span style="color: #000000;">
application.conf  consumer.properties  logback.xml  logger.xml  routes</span><span style="color: #000000;">
[admin@node21 kafka</span>-manager-<span style="color: #800080;">1.3</span>.<span style="color: #800080;">3.18</span>]$ sudo vi conf/<span style="color: #000000;">application.conf 
修改kafka</span>-<span style="color: #000000;">manager.zkhosts列表为自己的zk节点
kafka</span>-manager.zkhosts=<span style="color: #800000;">"</span><span style="color: #800000;">node21:2181,node22:2181,node23:2181</span><span style="color: #800000;">"</span></pre>
</div>
<p><img src="https://img2018.cnblogs.com/blog/1385722/201809/1385722-20180904170955757-527722011.png" alt="" /></p>
<h3>5.启动服务</h3>
<p>启动zk集群，kafka集群，再启动kafka-manager服务。</p>
<p>bin/kafka-<span>manager 默认的端口是9000，可通过 -Dhttp.port，指定端口; -Dconfig.file=conf/<span>application.conf指定配置文件:<br /></span></span></p>
<div class="cnblogs_code">
<pre>[admin@node21 kafka-manager-1.3.3.18]$ nohup bin/kafka-manager -Dconfig.file=conf/application.conf -Dhttp.port=8080 &amp;</pre>
</div>
<p>jps查看进程</p>
<p><img src="https://img2018.cnblogs.com/blog/1385722/201809/1385722-20180904224858511-1782476135.png" alt="" /></p>
<h3>6.编写服务启动脚本</h3>
<p>chmod +x kafka-manager.sh</p>
<div class="cnblogs_code">
<pre>nohup /opt/module/kafka-manager-<span style="color: #800080;">1.3</span>.<span style="color: #800080;">3.18</span>/bin/kafka-manager -Dconfig.file=/opt/module/kafka-manager-<span style="color: #800080;">1.3</span>.<span style="color: #800080;">3.18</span>/conf/application.conf -Dhttp.port=<span style="color: #800080;">8888</span> &gt;/opt/module/kafka-<span style="color: #000000;">ma
nager</span>-<span style="color: #800080;">1.3</span>.<span style="color: #800080;">3.18</span>/kafka-manager.log <span style="color: #800080;">2</span>&gt;&amp;<span style="color: #800080;">1</span> &amp;</pre>
</div>
<p>WebUI查看：<a href="http://node21:8888/" target="_blank">http://node21:8888/</a>&nbsp;出现如下界面则启动成功。</p>
<p><img src="https://img2018.cnblogs.com/blog/1385722/201809/1385722-20180924132859047-223914956.png" alt="" /></p>
<h2>三.kafka-manager配置</h2>
<h3>1.新建Cluster</h3>
<p>点击【Cluster】&gt;【Add Cluster】打开如下添加集群配置界面：输入集群的名字（如<code>Kafka-Cluster-1</code>）和 Zookeeper 服务器地址（如<code>localhost:2181</code>），选择最接近的Kafka版本</p>
<p><img src="https://img2018.cnblogs.com/blog/1385722/201809/1385722-20180904230236819-205031277.png" alt="" /></p>
<p>其他broker的配置可以根据自己需要进行配置，默认情况下，点击【保存】时，会提示几个默认值为<code>1</code>的配置错误，需要配置为<code>&gt;=2</code>的值。提示如下。</p>
<p><img src="https://img2018.cnblogs.com/blog/1385722/201809/1385722-20180904220631458-1124018059.png" alt="" /></p>
<p>新建完成后，保存运行界面如下：</p>
<p><img src="https://img2018.cnblogs.com/blog/1385722/201809/1385722-20180904220726779-1428283934.png" alt="" /></p>
<p><img src="https://img2018.cnblogs.com/blog/1385722/201809/1385722-20180904221415462-870371787.png" alt="" /></p>
<p><img src="https://img2018.cnblogs.com/blog/1385722/201809/1385722-20180904221451345-1470309564.png" alt="" /></p>
<h2>四.kafka-manager管理</h2>
<h3>1.新建主题</h3>
<p>Topic---Create</p>
<p><img src="https://img2018.cnblogs.com/blog/1385722/201809/1385722-20180904223238062-486196045.png" alt="" /></p>
<h3>2.查看主题</h3>
<p>Topic---list</p>
<p><img src="https://img2018.cnblogs.com/blog/1385722/201809/1385722-20180904223142410-1304100159.png" alt="" /></p>
<p>&nbsp;</p></div>

</body>
</html>
